package cn.oesoft.tennissystem.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import cn.oesoft.tennissystem.model.entity.TennisRacket;
/**
 * @Classname TennisRacketMapper
 * @Description TODO
 * @Date 2019-3-14 9:44
 * @Created by CrazyStone
 */

@Mapper
public interface TennisRacketMapper {
    // 根据id查询球拍信息
    @Select("SELECT * FROM t_tennis_racket WHERE id=#{id}")
    public TennisRacket getById(Integer id);
    
    // 根据球拍标题搜索球拍
    @Select("SELECT * FROM t_tennis_racket WHERE title like CONCAT('%',#{title},'%')")
    public List<TennisRacket> getByTitle(String title);

    // 发布球拍，同时使用@Options注解获取自动生成的主键id
    @Insert("INSERT INTO t_tennis_racket (number,headsize,weight,balance,length,string_pattern_main,string_pattern_cross,rec_tension_min,rec_tension_max,title,created,modified,tags,categories," +
            " allow_comment, thumbnail, content)" +
            " VALUES (#{number},#{headsize},#{weight},#{balance},#{length},#{stringPatternMain},#{stringPatternCross},#{recTensionMin},#{recTensionMax},#{title},#{created}, #{modified}, #{tags}, #{categories}," +
            " #{allowComment}, #{thumbnail}, #{content})")
    //@SelectKey(keyProperty="id", keyColumn="id",resultType=Integer.class,before = false, statement = { "select last_insert_id()" })
    @Options(useGeneratedKeys = true,keyProperty="id", keyColumn="id")
    public Integer insert(TennisRacket tennisRacket);

    // 球拍发分页查询
    @Select("SELECT * FROM t_tennis_racket ORDER BY id DESC")
    public List<TennisRacket> getWithPage();

    // 通过id删除球拍
    @Delete("DELETE FROM t_tennis_racket WHERE id=#{id}")
    public void deleteById(int id);

    // 站点服务统计，统计球拍数量
    @Select("SELECT COUNT(1) FROM t_tennis_racket")
    public Integer count();

    // 通过id更新球拍
    public Integer updateById(TennisRacket TennisRacket);
}
